<?php
##############################################
#
#   商铺
# @ Time : 2017-1-8 - 下午9:20:27
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Model;
use Admin\Model\AdminBaseModel;

class GoodsModel extends AdminBaseModel{
	/*商品表 */
	protected $tableName = 'goods';	
	
	/**
	 * 获取商品
	 */
	public function getGoods(){
		//return $this ->order('gid desc') -> select();
		$model = M();
		$sql = "select g.*, s.shop_name, l.lname, c.cname from mt_goods as `g` LEFT JOIN  mt_shop as `s` ON g.shopid = s.shopid
		 LEFT JOIN mt_locality as `l` ON g.lid = l.lid LEFT JOIN mt_category as `c` ON g.cid = c.cid";
		return $model -> query($sql);
		//var_dump($data);
	}
	
	/**
	 * 添加商品
	 */
	public function addGoods($data, $detail){
		$admin_model = new AdminBaseModel('goods');
		$detail_model = new AdminBaseModel('goods_detail');
		$result = $admin_model -> addData($data);
		$result_1 = $detail_model -> addData($detail);
		if($result && $result_1)
			return true;
		else
			return false;
	}
	
	/**
	* 删除商品
	* @param int $shopid
	*/
	public function deleteShop($shopid){
		return $this -> where("shopid = $shopid") -> delete();
	}
	
}